package com.itheima.edu.info.manager.controller;

import com.itheima.edu.info.manager.domain.Student;
import com.itheima.edu.info.manager.service.StudentService;
import jdk.swing.interop.SwingInterOpUtils;

import java.security.PublicKey;
import java.util.Scanner;

public class StudentController {
    private StudentService studentService = new StudentService();

    public void start() {
        Scanner sc = new Scanner(System.in);
        loop:
        while (true) {
            System.out.println("------欢迎使用学生管理系统------");
            System.out.println("1.添加学生  2.删除学生  3.修改学生  4.查看学生  5.退出");
            System.out.println("请输入您的选择:");
            int choose = sc.nextInt();

            switch (choose) {
                case 1:
                    addStudent();
                    break;
                case 2:
                    deleteStudentById();
                    break;
                case 3:
                    System.out.println("修改学生");
                    break;
                case 4:
                    findAllStudent();
                    break;
                case 5:
                    System.out.println("退出");
                    break loop;
                default:
                    System.out.println("你输入的选项有误,请重新输入");


            }
        }


    }


    public void deleteStudentById() {
        StudentService studentService = new StudentService();
        String delid;
        Scanner sc = new Scanner(System.in);
        while (true) {

            System.out.println("请输入要删除的学生id");
            delid = sc.next();
        }

        boolean b = studentService.deleteStudentById(delid);



        ;

    }
    public void findAllStudent(){
      StudentService studentService=new StudentService();
       //调用业务员的获取方法,得到学生的对象数组
        Student[] student=studentService.findAllStudent();
        //判断数组的内存地址.是否为null.
        if(student==null){
            System.out.println("查无信息,请添加后重试");
            return;
        }
        System.out.println("学号\t\t姓名\t年龄\t生日");
        for (int i = 0; i < student.length; i++) {
            Student students=student[i];
            if(students!=null){
                System.out.println(students.getAge()+  students.getId()+  students.getName()+   students.getBirthday());
            }
        }

    }



    public void addStudent() {
        System.out.println(studentService);
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入学生的学号");
        String id = sc.next();
        System.out.println("请输入学生的姓名");
        String name = sc.next();

        System.out.println("请输入学生的年龄");
        String age = sc.next();
        System.out.println("请输入学生的出生日期");
        String birthday = sc.next();
        Student student = new Student(id, name, age, birthday);
        StudentService studentService = new StudentService();
        boolean result = studentService.addStudent(student);
        if (result) {
            System.out.println("学生信息添加成功");
        } else {
            System.out.println("学生信息添加失败");
        }

    }
}















